//
//  BasicViewController.m
//  CToolBox
//
//  Created by SC on 16/7/22.
//  Copyright © 2016年 oyf. All rights reserved.
//

#import "BasicViewController.h"
#import "UINavigationBar+Awesome.h"
#import "UIImage+compressIMG.h"
#import "UIViewController+DismissKeyboard.h"

@interface BasicViewController ()<CTOperatorManagerDelegate>
{
    
}

@end


@implementation BasicViewController

- (BOOL)shouldAutorotate
{
    return NO;
}



-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//    [self setNoAnimationBarAlpha:1 color:HEXCOLOR(kColorBlue1, 1)];
    
    [self setNavigationController];
    [CSSManager shareManagerInstance].delegate = self;
    
}


-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [[UIApplication  sharedApplication].keyWindow endEditing:YES];
    
    [CSSManager shareManagerInstance].delegate = nil;
    
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = HEXCOLOR(kColorGray7, 1);
    
    [self publicSetting];
    [self setupForDismissKeyboard];
    
}



#pragma mark - Action

- (void)publicSetting
{
    // 暂时不修改导航栏下面的线
//    self.navigationController.navigationBar.shadowImage = [UIImage createImageWithColor:[UIColor clearColor]];
    
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.automaticallyAdjustsScrollViewInsets=NO;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"" style:0 target:nil action:nil];
    
    [self.navigationItem setBackBarButtonItem:bar];
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
                                                                    NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    
    [self.navigationController.navigationBar lt_setBackgroundColor:HEXCOLOR(kColorBlue1, 1)];
}


- (void)setBarAlpha:(CGFloat)alpha color:(UIColor *)color
{
    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
    }];
    
}

- (void)setNoAnimationBarAlpha:(CGFloat)alpha color:(UIColor *)color
{
    
    [self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
    
}

- (void)setBarTranslucent
{
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init]
                                                  forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    self.navigationItem.leftBarButtonItem = nil;
    
}

- (void)setNavigationControllerWithThemeColor:(UIColor *)themeColor
                                    tintColor:(UIColor *)tintColor
                                        alpha:(CGFloat)alpha{

    UIImage *shodowImage = nil;
    
    [self setNoAnimationBarAlpha:alpha color:themeColor];
    if(themeColor == [UIColor whiteColor]){
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
        // 暂时不修改导航栏下面的线
        // 设置导航栏下面线的颜色
        shodowImage = [UIImage createImageWithColor:[UIColor lightGrayColor]];
    }else{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        // 暂时不修改导航栏下面的线
        // 设置导航栏下面线的颜色
        shodowImage = [UIImage createImageWithColor:[UIColor clearColor]];
    }
    self.navigationController.navigationBar.titleTextAttributes = @{
                                                                    NSForegroundColorAttributeName:tintColor,
                                                                    
                                                                    NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};
    self.navigationController.navigationBar.tintColor = tintColor;
    // 暂时不修改导航栏下面的线
//    self.navigationController.navigationBar.shadowImage = shodowImage;

}


- (void)setNavigationController
{
    if(!self.navigationController){
        return;
    }

    UIColor *themeColor = HEXCOLOR(kColorBlue1, 1);
    UIColor *tintColor = [UIColor whiteColor];
    
    if([self.navigationController isKindOfClass:[BasicNavigationController class]]){
        BasicNavigationController *nVC = (BasicNavigationController *)self.navigationController;
        themeColor = nVC.themeColor;
        tintColor = nVC.tintColor;
    }
    
    [self setNavigationControllerWithThemeColor:themeColor tintColor:tintColor alpha:1];
    
    
    
//    [self setNoAnimationBarAlpha:1 color:[UIColor whiteColor]];
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
//    self.navigationController.navigationBar.titleTextAttributes = @{
//                                                                    NSForegroundColorAttributeName:HEXCOLOR(kColorBlack2, 1),
//                                                                    
//                                                                    NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};
//    self.navigationController.navigationBar.tintColor = HEXCOLOR(kColorBlack2, 1);
//    
//    self.navigationController.navigationBar.shadowImage = [UIImage createImageWithColor:HEXCOLOR(kColorGray7, 1)];
    
}

@end
